<template>
	<view class="face_box pdl-36 pdr-36">
		<view class="face_title flex-col">
			<view class="title fs42">人脸识别</view>
			<text class="desc mgt-19 fs22">信息仅用于授信或房贷审批，将严格保密</text>
		</view>
		<view class="face_container mgt-87">
			<view class="flex-ac flex-col">
				<image class="face_img mgb-50" src="/static/src/authentication/face_img.png" mode="aspectFill"></image>
				<text class="face_text fs28">请正对手机进行人脸识别</text>
			</view>
		</view>
		<view class="face_bottom mgt-120">
			<u-checkbox-group size="30" class="mgt-28">
				<u-checkbox v-model="checked" shape="circle">
					<view class="agreement_wrap fs24">
						我已阅读并同意
						<text class="agreement" @click="toAgreeMent">《人脸识别服务用户授权书》</text>
					</view>
				</u-checkbox>
			</u-checkbox-group>
			<u-button class="back_btn mgt-62 fs32" shape="circle" :hair-line="false" :ripple="true"
				throttle-time="2000" @click="handleBack">上一步</u-button>
			<u-button class="face_btn mgt-22" shape="circle" :ripple="true" type="primary" throttle-time="2000"
				@click="handleApply">开始人脸识别</u-button>
		</view>
	</view>
</template>
<script lang="ts" setup>
	import { useInformation } from '@/store/modules/index.ts'

	import { applyForReview } from "@/api/customer";
	
	import { ref } from 'vue';

	const user = useInformation()
	
	const checked = ref<boolean>(false)
	defineProps({
		currentNum: {
			type: Number,
			default: 0
		},
	})

	const emit = defineEmits<{
		(e : 'handleCurrent', data : number) : void;
	}>();

	const handleBack = () => {
		emit('handleCurrent', 2);
		uni.pageScrollTo({
			scrollTop: 0,
			duration: 300
		});
	}
	
	const toLink = () => {
		emit('handleCurrent', 4);
		uni.pageScrollTo({
			scrollTop: 0,
			duration: 300
		});
	}


	const handleApply = async() => {
		let ocrStatus;
		const currentIdentity = user.getIdentity();
		if (!checked.value) {
			uni.showToast({
				title: '请先阅读并同意人脸识别服务用户授权书',
				icon: 'none'
			});
			return;
		}
		if(currentIdentity.faceSide &&currentIdentity.backSide){
			ocrStatus=1
		}else{
			ocrStatus=2
		}
		const form = {
			username: currentIdentity.name,
			sex: currentIdentity.sex,
			nationality: currentIdentity.ethnicity,
			idcardNumber: currentIdentity.idNumber,
			idcardAddress: currentIdentity.address,
			issuingAuthority: currentIdentity.issueAuthority,
			frontPhoto: currentIdentity.faceSide,
			backPhoto: currentIdentity.backSide,
			idcardStartDate: currentIdentity.startDate,
			idcardEndDate: currentIdentity.endDate,
			idcardBirthday: currentIdentity.birthDate,
			residentialAddress:currentIdentity.residentialAddress + currentIdentity.fullAddress,
			maritalStatus:currentIdentity.maritalValue,
			educationalLevel:currentIdentity.educateValue,
			workUnit:currentIdentity.companyName,
			workIncome:currentIdentity.workIncome,
			workIndustry:currentIdentity.workIndustryValue,
			relationships:currentIdentity.relationships,
			ocrStatus:ocrStatus,
			idcardVerified:"Y"
		}
		let res = await applyForReview(form)
		if(res){
			if(res.code == 200){
				user.removeIdentity()
				uni.showToast({ title: '上传审核成功' })
				toLink()
			}
			
		}
		console.log(form.residentialAddress)
	}
</script>
<style lang="scss" scoped>
	@import '@/style/style.scss';

	.face_box {
		.face_title {
			.title {
				color: #333333;
				font-weight: bold;
				font-family: PingFang SC;
			}

			.desc {
				color: #666666;
				font-weight: 500;
				font-family: PingFang SC;
			}
		}

		.face_container {
			.face_img {
				width: 419rpx;
				height: 419rpx;
			}

			.face_text {
				color: #333333;
				font-weight: 500;
				font-family: PingFang SC;
			}
		}

		.face_bottom {
			.agreement_wrap {
				font-family: PingFang SC;

				.agreement {
					color: #3C51F2;
				}
			}

			.face_btn {
				background: #3C51F2;
				height: 100rpx;
			}
		}
	}
</style>